<div ng-controller="OrderCommodityInfoEditC">
        <div class="bg-light lter b-b wrapper-md">
            <h1 class="m-n font-thin h3">修改订单商品信息</h1>
        </div>
        <div class="wrapper-md">
            <div class="panel panel-default">
                <div class="table-responsive">
                    <form name="form" class="form-validation">
                        <div class="panel panel-default">
                            <div class="container-fluid text-center bg-light lter" >
                                <div class="row">
                                    <h3 style="display: inline-block;margin: 0 auto">订单商品列表</h3>
                                </div>
                                <!--<div class="row text-right">-->
                                    <!--<button type="button" class="btn btn-sm btn-success" ng-click="xxx()">选商品</button>-->
                                <!--</div>-->
                            </div>
                            <div class="container-fluid">
                                <div class="panel panel-default" ng-repeat="item in orderdetaildata.CommodityInfos" style="margin-bottom: 10px">
                                    <div class="panel-heading">
                                        <div>品牌：{{item.Commodity.Brand}}</div>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="col-xs-9 col-md-9">
                                                <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/{{item.Commodity.Format}}</div>
                                                <div>单价：
                                                    <span ng-show="orderdetaildata.IsLockPrice==1? true:isedit">{{item.Price | number:2}}</span>
                                                    <input ng-show="!isedit && orderdetaildata.IsLockPrice!=1" type="number" min="0" ng-model="item.Price" required>  元
                                                </div>
                                                <div>每吨运费：
                                                    <span ng-show="isedit">{{orderdetaildata.DeliveryPrice | number:2}}</span>
                                                    <input ng-show="!isedit" type="number" min="0" ng-model="orderdetaildata.DeliveryPrice" required>
                                                </div>
                                                <div>数量：
                                                <span ng-show="isedit">{{item.Count}}</span>
                                                    <input ng-show="!isedit" type="number" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" min="0" ng-model="item.Count" required>
                                                </div>
                                                <div>总运费：
                                                    {{orderdetaildata.DeliveryPrice*item.Weight| number:2}}
                                                </div>
                                                <div>总质量：
                                                     <span ng-show="isedit">{{item.Weight | number:3}}</span>
                                                     <input ng-show="!isedit" type="number" min="0" ng-model="item.Weight" required>t
                                                </div>
                                            </div>
                                            <div class="col-xs-3 col-md-3" style="text-align: center;">
                                                <button type="button" ng-show="isedit" class="btn btn-sm btn-success"  ng-click="edit(item)" style="margin: 5px">
                                                    编辑
                                                </button>
                                                <button type="button" ng-show="!isedit" class="btn btn-sm btn-success"  ng-click="edit(item)" style="margin: 5px">
                                                    完成
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel-footer">
                                        <div>总价：{{item.Weight | number:3}}*{{item.Price | number:2}}={{item.Weight*item.Price | number:2}}</div>
                                    </div>
                                </div>
                                <div class="row text-left container-fluid">
                                    <h4 style="display: inline-block">总价：{{orderdetaildata.Total | number:2}}</h4>
                                </div>
                                <div class="row text-right container-fluid">
                                    <button type="button" class="btn btn-success" ng-disabled="form.$invalid" ng-click="ordersub()">确认修改</button>
                                    <button type="button" class="btn btn-default" ng-click="abolish()">取消修改</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<script>
    angular.module('app')
        //更改计划单商品控制器
    .controller("OrderCommodityInfoEditC", function ($scope, $state, $stateParams, $http) {
        $scope.id = JSON.parse($stateParams.orderid);
        $scope.isedit = true;
        //获取计划单详细数据
        $http({
            url: "../api/Order/Detail?id=" + $scope.id,
            method: "GET"
        })
            .then(function (res) {
                $scope.orderdetaildata = res.data;
            })
            .then(function (error) {
                if (error) {
                    console.log("error");
                }
            });
        $scope.edit = function (item) {
            $scope.isedit = !$scope.isedit;
            $scope.sum();
        };
        //计算总价方法
        $scope.sum = function () {
            $scope.orderdetaildata.Total = 0;
            for (var i = 0; i < $scope.orderdetaildata.CommodityInfos.length; i++) {
                $scope.orderdetaildata.Total += $scope.orderdetaildata.CommodityInfos[i].Price * $scope.orderdetaildata.CommodityInfos[i].Weight;
                
            }
        };
        //保存更改
        $scope.ordersub = function () {

            $http.post('../api/OrderManager/CommodityInfoEdit', $scope.orderdetaildata)
                .success(function (res) {
                    if (res.State <= 0) {
                        alert(res.Msg);
                    } else {
                        alert("添加成功");
                        $state.go('app.Order_Detail', {
                            orderid: JSON.stringify($scope.id)
                        });
                    }

                });
        };
        //取消更改
        $scope.abolish = function () {
            $state.go('app.Order_Detail', {
                orderid: JSON.stringify($scope.id)
            });
        }

    })
</script>